set type double, permanently

/* Export Part 1 CBC allocations */
use allocations.dta, clear
keep if pnum <= 20
outsheet subject pnum dshares* dshares2 price1 price2 using garp/dalloc2.csv if numCompanies==2, comma noquote noname nolabel replace
outsheet subject pnum dshares1 dshares2 dshares3 price1 price2 price3 using garp/dalloc3.csv if numCompanies==3, comma noquote noname nolabel replace
outsheet subject pnum dshares1 dshares2 dshares3 dshares4 dshares5 dshares6 price1 price2 price3 price4 price5 price6 using garp/dalloc6.csv if numCompanies==6, comma noquote noname nolabel replace

/* Export Part 1 rule allocations */
use allocations.dta, clear
keep if pnum <= 20
outsheet subject pnum rshares1 rshares2 price1 price2 using garp/ralloc2.csv if numCompanies==2, comma noquote noname nolabel replace
outsheet subject pnum rshares1 rshares2 rshares3 price1 price2 price3 using garp/ralloc3.csv if numCompanies==3, comma noquote noname nolabel replace
outsheet subject pnum rshares1 rshares2 rshares3 rshares4 rshares5 rshares6 price1 price2 price3 price4 price5 price6 using garp/ralloc6.csv if numCompanies==6, comma noquote noname nolabel replace

/* Allocations for comparison between choises in the two parts */
use subjects.dta, clear
keep if diffRule /* Limit sample to subjects who chose a different rule in Part 2 */
merge 1:m subject using allocations, keep(3)

/* Export Part 1 + Part 2 allocations for the subjects who chose CBC in Part 2 */
preserve
keep if !daOrRule /* Limit sample to subjects who chose CBC in Part 2 */

outsheet subject pnum dshares1 dshares2 price1 price2 using garp/p2dalloc2.csv if numCompanies==2, comma noquote noname nolabel replace
outsheet subject pnum dshares1 dshares2 dshares3 price1 price2 price3 using garp/p2dalloc3.csv if numCompanies==3, comma noquote noname nolabel replace
outsheet subject pnum dshares1 dshares2 dshares3 dshares4 dshares5 dshares6 price1 price2 price3 price4 price5 price6 using garp/p2dalloc6.csv if numCompanies==6, comma noquote noname nolabel replace

/* Export Part 1 + Part 2 allocations for the subjects who chose Rule in Part 2 */
restore
keep if daOrRule /* Limit sample to subjects who chose Rule in Part 2 */
keep if pnum <= 20

/* Export their Part 1 CBC allocations */
outsheet subject pnum dshares1 dshares2 price1 price2 using garp/p1ralloc2.csv if numCompanies==2, comma noquote noname nolabel replace
outsheet subject pnum dshares1 dshares2 dshares3 price1 price2 price3 using garp/p1ralloc3.csv if numCompanies==3, comma noquote noname nolabel replace
outsheet subject pnum dshares1 dshares2 dshares3 dshares4 dshares5 dshares6 price1 price2 price3 price4 price5 price6 using garp/p1ralloc6.csv if numCompanies==6, comma noquote noname nolabel replace

/* Export their Part 2 rule allocations */
outsheet subject pnum p2rshares1 p2rshares2 price1 price2 using garp/p2ralloc2.csv if numCompanies==2, comma noquote noname nolabel replace
outsheet subject pnum p2rshares1 p2rshares2 p2rshares3 price1 price2 price3 using garp/p2ralloc3.csv if numCompanies==3, comma noquote noname nolabel replace
outsheet subject pnum p2rshares1 p2rshares2 p2rshares3 p2rshares4 p2rshares5 p2rshares6 price1 price2 price3 price4 price5 price6 using garp/p2ralloc6.csv if numCompanies==6, comma noquote noname nolabel replace
